package com.doublethread.easymart.modules.comment.controller;

import com.doublethread.easymart.common.result.PageResult;
import com.doublethread.easymart.common.result.Result;
import com.doublethread.easymart.modules.comment.dto.CommentBatchUpdateStatusDTO;
import com.doublethread.easymart.modules.comment.dto.CommentQueryDTO;
import com.doublethread.easymart.modules.comment.dto.CommentReplyDTO;
import com.doublethread.easymart.modules.comment.dto.CommentUpdateStatusDTO;
import com.doublethread.easymart.modules.comment.service.CommentService;
import com.doublethread.easymart.modules.comment.vo.AdminCommentVO;
import com.doublethread.easymart.modules.comment.vo.CommentStatisticsVO;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 管理端评论控制器
 */
@RestController
@RequestMapping("/api/admin/comments")
@RequiredArgsConstructor
public class AdminCommentController {

    private final CommentService commentService;

    /**
     * 获取评论列表
     */
    @GetMapping
    public Result<PageResult<AdminCommentVO>> getCommentList(CommentQueryDTO queryDTO) {
        PageResult<AdminCommentVO> result = commentService.getAdminCommentList(queryDTO);
        return Result.success(result);
    }

    /**
     * 获取评论详情
     */
    @GetMapping("/{id}")
    public Result<AdminCommentVO> getCommentDetail(@PathVariable Long id) {
        AdminCommentVO result = commentService.getAdminCommentDetail(id);
        return Result.success(result);
    }

    /**
     * 更新评论状态
     */
    @PutMapping("/{id}/status")
    public Result<Void> updateCommentStatus(@PathVariable Long id,
                                            @RequestBody @Valid CommentUpdateStatusDTO dto) {
        commentService.updateCommentStatus(id, dto);
        return Result.success();
    }

    /**
     * 回复评论
     */
    @PutMapping("/{id}/reply")
    public Result<Void> replyComment(@PathVariable Long id,
                                     @RequestBody @Valid CommentReplyDTO dto) {
        commentService.replyComment(id, dto);
        return Result.success();
    }

    /**
     * 批量更新评论状态
     */
    @PutMapping("/batch/status")
    public Result<Void> batchUpdateCommentStatus(@RequestBody @Valid CommentBatchUpdateStatusDTO dto) {
        commentService.batchUpdateCommentStatus(dto);
        return Result.success();
    }

    /**
     * 获取评论统计信息
     */
    @GetMapping("/statistics")
    public Result<CommentStatisticsVO> getCommentStatistics() {
        CommentStatisticsVO result = commentService.getAdminCommentStatistics();
        return Result.success(result);
    }

    /**
     * 获取商品评论统计信息
     */
    @GetMapping("/statistics/product/{productId}")
    public Result<CommentStatisticsVO> getProductCommentStatistics(@PathVariable Long productId) {
        CommentStatisticsVO result = commentService.getAdminProductCommentStatistics(productId);
        return Result.success(result);
    }

    /**
     * 批量删除评论
     */
    @DeleteMapping("/batch")
    public Result<Void> batchDeleteComments(@RequestBody List<Long> commentIds) {
        commentService.batchDeleteComments(commentIds);
        return Result.success();
    }
}
